import csv

users = [
    {"name":"张安","age":22,"username":"za","password":"123"},
    {"name":"李四","age":22,"username":"za","password":"123"},
    {"name":"王五","age":23,"username":"za","password":"123"},
    {"name":"赵六","age":24,"username":"za","password":"123"},
    {"name":"筑起","age":25,"username":"za","password":"123"},
    {"name":"站六","age":21,"username":"za","password":"123"},
    {"name":"草擦","age":22,"username":"za","password":"123"},
    {"name":"刘备","age":23,"username":"za","password":"123"},
]
with open('user.csv','w',encoding='utf-8',newline='') as f:
    fname = ['name','age','username','password']
    writer = csv.DictWriter(f,fieldnames=fname)
    writer.writeheader()
    writer.writerows(users)